package answers;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class MultipleChoiceAnswer implements IAnswer
{

	public MultipleChoiceAnswer(List<String> answerSet)
	{
		this.answerSet = new LinkedList<String>(answerSet);
	}
	
	@Override
	public boolean compare(IAnswer other)
	{
		if((other instanceof MultipleChoiceAnswer) == false)
		{
			return false;
		}
		else
		{
			MultipleChoiceAnswer otherXchoice = (MultipleChoiceAnswer)other;
			List<String> myData = new LinkedList<String>(answerSet);
			List<String> otherData = new LinkedList<String>(otherXchoice.answerSet);
			Collections.sort(myData);
			Collections.sort(otherData);
			return myData.equals(otherData);
		}
	}

	@Override
	public String getText()
	{
		String retval = new String();
		Iterator<String> iter = answerSet.iterator();
		while(iter.hasNext())
		{
			retval += iter.next() + ",";
		}
		return retval;
	}

	List<String> answerSet;
}
